package com.example.demo.controller;

import com.example.demo.entity.MailContent;
import com.example.demo.util.LogUtils;
import com.example.demo.util.MailSendSmtp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2019/4/12.
 * 测试mybatis多数据源
 */
@Api(tags = "邮箱接口")
@RestController
@RequestMapping("/api/email")
public class EmailController {

    @Autowired
    private MailSendSmtp mailSendSmtp;

    private static final Logger logger = LoggerFactory.getLogger(EmailController.class);

    @PostMapping("/send")
    @ApiOperation(httpMethod = "POST", value = "发送邮件")
    public String send(@RequestBody MailContent mailContent) {
        mailSendSmtp.send(mailContent);
        return "index";
    }

    @GetMapping("/log")
    @ApiOperation(httpMethod = "GET", value = "日志测试")
    public String log() {

//        logger.info("");
        LogUtils.outLogInfo("mail", "sendMail", String.format("发送邮件，toEmail=%s，text=%s", "123456@qq.com", "测试邮件内容"));
        LogUtils.outLogError("mail", "sendMail", String.format("发送邮件，toEmail=%s，text=%s，错误原因：%s", "123456@qq.com", "测试邮件内容", "超时"));
        return "index";
    }

}
